\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{macros/mysigmod}

\RequirePackage{ifthen}
\newboolean{mysigmod@alternate}
\setboolean{mysigmod@alternate}{false}
\DeclareOption{alternate}{
  \setboolean{mysigmod@alternate}{true}
}
\ExecuteOptions{}
\ProcessOptions

% Restore \footnotesize:
%
\renewcommand{\footnotesize}{\small}

% SIG style defines a very odd \paragraph and no \subparagraph; let us
% restore them to something reasonable below:
%
\ifthenelse{\boolean{mysigmod@alternate}}{
  \def\paragraph{%
    \@startsection{paragraph}{4}{\z@}{6\p@ \@plus \p@ \@minus \p@}%
    {-5\p@}{\bfseries}%
  }
  \def\subparagraph{%
    \@startsection{subparagraph}{5}{\parindent}{6\p@ \@plus \p@ \@minus \p@}%
    {-5\p@}{\itshape}%
  }
}{
  \setlength{\parskip}{10.5pt}
  \def\paragraph{%
    \@startsection{paragraph}{4}{\z@}{-10\p@ \@plus -4\p@ \@minus -2\p@}%
    {-5\p@}{\bfseries}%
  }
  \def\subparagraph{%
    \@startsection{subparagraph}{5}{\parindent}{-10\p@ \@plus -4\p@ \@minus -2\p@}%
    {-5\p@}{\itshape}%
  }
}

% SIG style does not define \abovecaptionskip and \belowcaptionskip
% but hard-code them in \@makecaption. Following is adapted from the
% standard article.cls, and allows papermac.tex's \tightfloats to
% work:
%
\newlength{\abovecaptionskip}
\newlength{\belowcaptionskip}
\setlength\abovecaptionskip{10\p@}
\setlength\belowcaptionskip{0\p@}
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{\textbf{#1: #2}}%
  \ifdim \wd\@tempboxa >\hsize
    \textbf{#1: #2}\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}

% SIG style does not define @restonecol; following is added to coax
% algorithm2e.sty:
%
\newif\if@restonecol

% SIG style defines its own proof; we do not want it to conflict with
% amsthm.sty:
%
\let\proof\@undefined
\let\endproof\@undefined

% SIG style really messes up the bibliography; following is added to coax
% natbib.sty:
%
% First, undo the damage:
%
\let\bibindent\@undefined
\let\thebibliography\@undefined
\let\newblock\@undefined
%
% The following is standard:
%
\renewcommand\@biblabel[1]{[#1]}
%
% The following \bibindent, thebibliography, and \newblock are taken
% from standard article.cls:
%
\newdimen\bibindent
\setlength\bibindent{1.5em}
\newenvironment{thebibliography}[1]
     {\section*{\refname}%
      \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\newcommand\newblock{\hskip .11em\@plus.33em\@minus.07em}

% Apply our own customization:
%
\input{macros/papermac}

\ifthenelse{\boolean{mysigmod@alternate}}{
  % The style hard-codes a 12pt-skip, so all above-skip specifications
  % for \section, etc. are increased by 12pt below:
  \TweakSectionSpacing
    {22\p@ \@plus 4\p@ \@minus 2\p@}
    {20\p@ \@plus 2\p@ \@minus 1\p@}
    {20\p@ \@plus 2\p@ \@minus 1\p@}
    {18\p@ \@plus 1\p@ \@minus 1\p@}
    {18\p@ \@plus 1\p@ \@minus 1\p@}
    {4\p@}
}{
  % Effectively 0.5pt skip, because \parskip is 10.5pt.
  \TweakSectionSpacing
    {-10\p@ \@plus -4\p@ \@minus -2\p@}
    {-10\p@ \@plus -4\p@ \@minus -2\p@}
    {-10\p@ \@plus -4\p@ \@minus -2\p@}
    {-10\p@ \@plus -4\p@ \@minus -2\p@}
    {-10\p@ \@plus -4\p@ \@minus -2\p@}
    {-10\p@}
}
